#pragma once
#include <iostream>
#include <vector>

namespace ns_bitmap
{
    template <size_t N>
    class bit_map
    {
    public:
        bit_map()
        {
            _bits.resize(N/8+1);
        }

        void set(int x)
        {
            int i = x / 8;
            int j = x % 8;
            _bits[i] |= (1 << j);
        }

        void reset(int x)
        {
            int i = x / 8;
            int j = x % 8;
            _bits[i] &= ~(1<<j);
        }

        bool test(int x)
        {
            int i = x / 8;
            int j = x % 8;

            return _bits[i] & (1 << j);
        }

        ~bit_map()
        {}
    private:
        std::vector<char> _bits;
    };

    template <size_t N>
    class two_bitMap
    {
    public:
        two_bitMap(){}

        void set(int x)
        {
            if(!_bit1.test(x) && !_bit2.test(x)) //00 -> 01
            {
                _bit1.set(x);
            }
            else if(_bit1.test(x) && !_bit2.test(x))  //01 -> 11
            {
                _bit2.set(x);
            }
            std::cout << "x = " << x << ", " << _bit1.test(x) << " " << _bit2.test(x) << std::endl;
        }

        void PrintNum()
        {
            for(size_t i = 0;i < N;++i)
            {
                if(_bit1.test(i) && !_bit2.test(i))
                {
                    std::cout << i << std::endl;
                }
            }
        }

        ~two_bitMap(){}
    private:
        bit_map<N> _bit1;
        bit_map<N> _bit2;
    };
}